package com.lzb.newloan.utils;

import java.io.ByteArrayOutputStream;


import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.util.Base64;

public class BitmapexchangeImage {
	/**
	 
	 * 将bitmap转换成base64字符串
	 * 
	 * @param bitmap
	 * @return base64 字符串
	 */
	public String bitmaptoString(Bitmap bitmap, int bitmapQuality) {
	 
	// 将Bitmap转换成字符串
	String string = null;
	ByteArrayOutputStream bStream = new ByteArrayOutputStream();
	bitmap.compress(CompressFormat.PNG, bitmapQuality, bStream);
	byte[] bytes = bStream.toByteArray();
	string = Base64.encodeToString(bytes, Base64.DEFAULT);
	return string;
	}
	 
	/**
	 * 将base64转换成bitmap图片
	 * 
	 * @param string base64字符串
	 * @return bitmap
	 */
	public Bitmap stringtoBitmap(final String str) {
	// 将字符串转换成Bitmap类型
	Bitmap bitmap = null;
	try {
	byte[] bitmapArray;
	bitmapArray =android.util.Base64.decode(str, Base64.DEFAULT);
	bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0,
	bitmapArray.length);
	} catch (Exception e) {
	e.printStackTrace();
	}
	return bitmap;
	}
}
